﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace wUniAppPCL.IO
{
  // pripravene nie len pre XML serializaciu ale aj pre JSON, Binary pripadne text parsing do buducna
  public interface IwSerializer<T>
  {
    T Deserialize(Stream stream);
    void Serialize(Stream stream, T source);
  }

  public class wXmlSerializer<T> : IwSerializer<T>  where T : new()
  {
    public wXmlSerializer()
    {
      xs = new XmlSerializer(typeof(T));
    }

    XmlSerializer xs; 
    public T Deserialize(Stream stream)
    {
      try
      {
        return (T) xs.Deserialize(stream);
      }
      catch// (Exception ex)
      {
        throw;
      }
    }

    public void Serialize(Stream stream, T source)
    {
      try
      {
        xs.Serialize(stream, source);
      }
      catch // (Exception ex)
      {
        throw;
      }
    }
  }
}
